﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using System.Web.Mvc;

namespace Bzure.Mvc
{
    public static class ThemeExtensions
    {
        public static string GetThemeName(this RequestContext controllerContext)
        {
            return Actor.Me.ThemeName;
        }
    }
    public static class ThemeHelper
    {
        public static string CreateThemeViewPath(string ThemeName, string AreaName, string partialViewName)
        {
            if (string.IsNullOrEmpty(partialViewName))
                throw new ArgumentNullException("partialViewName is null");
            partialViewName = partialViewName.Trim();
            if (partialViewName.StartsWith(@"~"))
                partialViewName = partialViewName.Remove(0, 1);
            if (partialViewName.StartsWith(@"/"))
                partialViewName = partialViewName.Remove(0, 1);
            if (partialViewName.StartsWith(@"\"))
                partialViewName = partialViewName.Remove(0, 1);
            if (string.IsNullOrEmpty(AreaName))
            {
                return string.Format("/Themes/{0}/{1}", ThemeName, partialViewName);
            }
            else
            {
                return string.Format("/Themes/{0}/Areas/{1}/{2}", ThemeName, AreaName, partialViewName);
            }
        }

        public static string CreateGenericThemeViewPath(string AreaName, string partialViewName)
        {
            if (string.IsNullOrEmpty(partialViewName))
                throw new ArgumentNullException("partialViewName is null");
            partialViewName = partialViewName.Trim();
            if (partialViewName.StartsWith(@"~"))
                partialViewName = partialViewName.Remove(0, 1);
            if (partialViewName.StartsWith(@"/"))
                partialViewName = partialViewName.Remove(0, 1);
            if (partialViewName.StartsWith(@"\"))
                partialViewName = partialViewName.Remove(0, 1);
            if (string.IsNullOrEmpty(AreaName))
            {
                return string.Format("/GenericTheme/{0}",  partialViewName);
            }
            else
            {
                return string.Format("/GenericTheme/Areas/{0}/{1}",  AreaName, partialViewName);
            }
        }
    }
}
